//
//  UIViewController+HUD.m
//  JFPayMent
//
//  Created by lixiqing on 2017/7/30.
//  Copyright © 2017年 XQ. All rights reserved.
//

#import "UIViewController+HUD.h"

@implementation UIViewController (HUD)
-(void)showSuccess:(NSString *)success{
  
    MBProgressHUD *HUD=[self HUD];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=success;
    [HUD hideAnimated:YES afterDelay:2.f];
}
-(void)showSuccess:(NSString *)success duration:(CGFloat)second{
   
    MBProgressHUD *HUD=[self HUD];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=success;
    [HUD hideAnimated:YES afterDelay:second];
}
-(void)showError:(NSString *)error
{
    MBProgressHUD *HUD=[self HUD];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=error;
    [HUD hideAnimated:YES afterDelay:2.f];
}
-(void)showError:(NSString *)error duration:(CGFloat)second{
    
    MBProgressHUD *HUD=[self HUD];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=error;
    [HUD hideAnimated:YES afterDelay:second];
}
-(void)showMessage:(NSString *)message
{
    MBProgressHUD *HUD=[self HUD];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=message;
    [HUD hideAnimated:YES afterDelay:2.f];
}
-(void)showWaiting
{
    [self HUD];
}
-(void)showLoading
{
   MBProgressHUD *HUD=[self HUD];
    HUD.label.text=@"正在加载";
    
}
-(void)showLoadingWithMessage:(NSString *)message
{
    MBProgressHUD *HUD=[self HUD];
    HUD.label.text=message;
    
}
-(void)showSaving
{
    MBProgressHUD *HUD=[self HUD];
    HUD.label.text=@"正在保存";
   
}
-(MBProgressHUD*)HUD
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.userInteractionEnabled = NO;
    HUD.contentColor=[UIColor whiteColor];
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
    return  HUD;
}
-(void)hideHUD
{
    [MBProgressHUD hideHUDForView:[self getView] animated:YES];
}
-(UIView *)getView
{
    UIView *view;
    if (self.navigationController.view) {
        view=self.navigationController.view;
    }else
    {
        view=self.view;
    }
    return view;
}
-(UIView*)tipViewImage:(NSString*)imag title:(NSString*)title
{
    UIView * allView = [[UIView alloc]init];
    allView.userInteractionEnabled = YES;
    UIImageView * imgView = [[UIImageView alloc]init];
    UILabel * titleLabel = [[UILabel alloc]init];
    if (imag) {
       UIImage * img = [UIImage imageNamed:imag];
        imgView.image = img;
        imgView.frame = CGRectMake(0, 0, img.size.width, img.size.height);
        
    }
    if (title) {
        titleLabel.text = title;
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.textColor = [UIColor lightGrayColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.numberOfLines = 0;
        titleLabel.frame = CGRectMake(0, CGRectGetMaxY(imgView.frame)+5, APP_WIDTH, 40);
    }
    [allView addSubview:imgView];
    [allView addSubview:titleLabel];
    allView.size = CGSizeMake(APP_WIDTH, imgView.frame.size.height+titleLabel.frame.size.height+5);
    allView.centerXX = [self getView].centerXX;
    allView.centerYY = [self getView].centerYY-64;
    imgView.centerXX = allView.centerXX;
    
    return allView;
}
//-(void)showAlertTitle:(NSString*)title detailTitle:(NSString*)detailTitle sureBtnTitle:(NSString*)btnTitle jumpToVC:(UIViewController*)vc
//{
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:detailTitle preferredStyle:UIAlertControllerStyleAlert ];
//    __weak typeof(self)weakself = self;
//    UIAlertAction * OKAction = [UIAlertAction actionWithTitle:btnTitle style:UIAlertActionStyleDefault  handler:^(UIAlertAction * _Nonnull action) {
//        if (vc) {
//           [weakself.navigationController pushViewController:vc animated:YES]; 
//        }
//        
//    }];
//    [OKAction setValue:JFGreenColor forKey:@"titleTextColor"];
//    [alertController addAction:OKAction];
//    
//    [self presentViewController:alertController animated:YES completion:nil];
//
//}


@end
